﻿
/**
* equalHeightBlocks: Define a mesma altura para blocos "A" e "B" dentro de um bloco "X".
* Autor: Sidnei Szirkowski - 16/nov/2010
* 
* Exemplo de uso:
* $('X').equalHeightBlocks( {'colA':'A', 'colB':'B'} );
* 
* Defaults:
* colA  = '.block-name'
* colB  = '.block-columns'
**/
(function( $ ){
	$.fn.equalHeightBlocks = function( options ) {
		
		var defaults = {
				colA: '.block-name',
				colB: '.block-columns',
				colorize: false
		};
		
		var options = $.extend(defaults, options);
		
		return this.each(function() {
			$this    = $(this);
			$colA    = $this.find(options.colA);
			$colB    = $this.find(options.colB);
			
			$colAHeight = $colA.height();
			$colBHeight = $colB.height();

			if ($colBHeight > $colAHeight) {
				if ( browserIE7 ) {
					$colA.css('height', $colBHeight);
				} else {
					$colA.css('height', $colBHeight - 0);
				}
			} else {
				$colB.css('height', $colAHeight - 0);
			}
			
			if (options.colorize) {
				$structure = $this.find(options.colA + ' .sequence').html();
				$this.addClass('custom-' + $structure);
			}
			
		});
	};
})( jQuery );


/**
* boxExpandItens: Mostra itens de uma lista.
* Autor: Sidnei Szirkowski - 1/dez/2010
* 
* Exemplo de uso:
* $('X').boxExpandItens({itens:10, count:false, cookie:false});
* 
* Defaults:
* itens  = 5
* count  = true
* cookie = true
**/
(function( $ ){
	$.fn.boxExpandItens = function( options ) {
		
		var defaults = {
				itens: 5,
				count: true,
				cookie: true
		};
		
		var options = $.extend(defaults, options);
		
		return this.each(function() {
			$this     = $(this);
			$itens    = $this.find('.box-expand-itens');
			
			//Adiciona total de itens
			if (options.count) {
				$this.find('.box-expand-count').html('(' + $itens.children().size() + ')' );
			}
			
			//Mostra/oculta itens
			if (options.itens == 0) {
				$itens.children().hide('normal');
				
			} else if (options.itens == 'all' || options.itens == null || options.itens == '') {
				$itens.children().show('normal');
				
			} else if (options.itens > 0) {
				$itens.children().hide();
				$itens.find(':nth-child(-n+' + options.itens + ')').show('normal');
			}
			
			//Grava opção em cookie
			if (options.cookie) {
				$.cookie('search-mysearch', options.itens);
			}
			
			//Altera estado do botão
			$this.find('.list-button A.active').removeClass('active');
			$('.box-expand-item-' + options.itens).addClass('active');
			
		});
	};
})( jQuery );

